package com.code.coinprice.controllers;

import com.code.coinprice.managers.HttpManager;
import com.code.coinprice.utils.ResponseUtil;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class HttpController {

    @Resource
    private HttpManager httpManager;

    @GetMapping("/get-request")
    public Object getRequest(@RequestParam String apiKey) {
        String url = "https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest";
        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
        params.add("start", "1");
        params.add("limit", "5000");
        params.add("convert", "USD");
        ResponseEntity<Object> responseEntityObj = httpManager.sendGetRequest(url, "X-CMC_PRO_API_KEY", apiKey, params);
        return ResponseUtil.ok(responseEntityObj);
    }

}
